<%--
  Created by IntelliJ IDEA.
  User: 86181
  Date: 2022/10/18
  Time: 9:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-table.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.js"></script>
    <script src="js/jquery.validate.js"></script>
    <script src="js/jquery.form.js"></script>
    <script src="js/messages_zh.js"></script>
</head>
<body>
<!--头部-->
<div class="modal-header">
    <button class="close" data-dismiss="modal">&times;</button>
    <h3>修改菜单</h3>
</div>
<form id="updatemenus" class="form-horizontal">
    <!--身体-->
    <div class="modal-body">
        <div class="form-group">
            <label class="control-label col-md-2">父菜单名称:</label>
            <div class="col-md-10">
                <input type="hidden" id="id" name="id">
                <select id="parentid" name="parentid">
                    <option value="0">我就是爹</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2" for="name">菜单名称:</label>
            <div class="col-md-10">
                <input type="text" id="name" name="name" class="form-control" placeholder="请输入菜单名称" required>
            </div>
        </div>
    </div>
    <!--底部-->
    <div class="modal-footer">
        <div>
            <input type="button" id="btn1" value="修改菜单" class="btn btn-info col-md-2 col-md-offset-2">
            <input type="reset" value="重置" class="btn btn-success col-md-2 col-md-offset-3">
            <input type="button" value="关闭" class="btn btn-danger col-md-2 col-md-offset-1">
        </div>

    </div>
</form>

<script>
    $("#btn1").click(function () {
        var params={
            url: 'updatemenus.action',
            type:'post',
            dataType: 'json',
            success:function (data) {
                alert(data.msg);
                location.href="menus.jsp"
            }
        }
        $("#updatemenus").ajaxSubmit(params)
    })
    //加载数据
    $(function () {
        var id='${param.id}'
        alert(id)
        $.ajax({
            url:'querybymenusid.action/'+id,
            type:'post',
            dataType:'json',
            success:function (data) {
                console.log(data)
                $("#id").val(data.id);
                $("#name").val(data.name);
            }
        })
        $.ajax({
            url: "queryByMenusMenuid.action",
            type: "post",
            dataType: "json",
            success:function (data) {
                for(var i=0; i<data.length;i++){
                    var op=$("<option></option>")
                    op.val(data[i].id);
                    op.text(data[i].name);
                    $("#parentid").append(op);
                }
            }
        })
    })
</script>
</body>
</html>
